package cn.swanit.common.base.annotation.validator;

import cn.hutool.core.util.IdcardUtil;
import cn.swanit.common.base.annotation.IdentityCardNumber;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IdentityCardNumberValidator implements ConstraintValidator<IdentityCardNumber, Object> {

    @Override
    public void initialize(IdentityCardNumber identityCardNumber) {
    }

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        return IdcardUtil.isValidCard18(o.toString()) || IdcardUtil.isValidCard15(o.toString());
    }
}